-
Book Overview & Buying
-
Table Of Contents
R Graph Essentials
Now, let's learn how to create a histogram using geom = "histogram" and control the bin width using the argument binwidth. In this example, we will create a histogram of the heights of the patients and select a bin width of 10 cm. The syntax is as follows:
qplot(HEIGHT, geom = "histogram", ylab = "COUNT", xlab = "HEIGHT", binwidth = 10)
Here is our histogram:

Our histogram has a rather chunky appearance, and we may wish to change the color and other attributes of the default histogram. By the way, note what happens if we use the syntax color = I("blue"):
qplot(HEIGHT, geom = "histogram", ylab = "COUNT", xlab = "HEIGHT", binwidth = 10, color = I("blue"), fill = I("wheat"))
Now the histogram looks like this:

We get blue outlines for the bars and the axes. Remember that, for histograms, the color argument controls the color of the histogram outlines, while the argument fill controls the color of the bars.
Change the font size
Change margin width
Change background colour